
function putMsg(data) {
  var msg = data.message;
  var nick = data.sendNickname;
  var shakeStatus = data.shake;
  switch (data.msgtype) {
    case "init":
      layer.msg(msg);
      break;
    case "text":
      if (data.sendUser == userId) {
        setMessageInnerHTML2(nick, text2Emoji2(msg), shakeStatus);
      } else {
        setMessageInnerHTML(nick, text2Emoji2(msg), shakeStatus);
      }
      break;
    case "img":
      if (data.sendUser == userId) {
        setImgInnerHTML2(nick, msg);
      } else {
        setImgInnerHTML(nick, msg);
      }
      break;
    case "file":
      if (data.sendUser == userId) {
        setFileInnerHTML2(nick, msg, data.filename);
      } else {
        setFileInnerHTML(nick, msg, data.filename);
      }
      break;
    case "bing":
      document.getElementById("userId").value = data.id;
      $("body").css("background-image", "url(" + msg + ")");
      break;
    default:
      break;
  }
}



function sendImg(type) {
  var formData = new FormData();
  let file = document.getElementById(type).files[0];
  formData.append("file", file);
  formData.append("parameter", "file");

  $.ajax({
    url: "http://localhost:7071/ddc-css/common/fileUpload",
    dataType: "json",
    type: "POST",
    async: false,
    data: formData,
    processData: false, // 使数据不做处理
    contentType: false, // 不要设置Content-Type请求头
    success: function (data) {
      console.log(data);
      if (data.code == 0) {
        send(data.data, type, file.name);
      }
    },
    error: function (response) {
      console.log(response);
    },
  });
}

function loadEmoji() {
  $("#text").emoji({
    button: "#emoji",
    showTab: true,
    animation: "slide",
    icons: [
      {
        name: "QQ表情",
        path: "dist/img/qq/",
        maxNum: 154,
        file: ".gif",
      },
      {
        name: "坏坏GIF",
        path: "dist/img/huaiGif/",
        maxNum: 26,
        file: ".gif",
      },
      {
        name: "猥琐萌",
        path: "dist/img/xiaoren/",
        maxNum: 186,
        file: ".gif",
      },
    ],
  });
}

  // 清空屏幕
  function emptyScreen() {
    $("#message").empty();
  }
